// page/pay/pay.js
var util = require("../../utils/util.js");
Page({
  data: {
    price: 2.00,
    id: "xym987654321",
    detail:{}
  },
  onLoad: function (options) {
    var id = options.id;
    var price = options.price;
    this.setData({
      id: id,
      price: price,
      detail: JSON.parse(options.detail)
    });
  },
  onConfirmPay: function () {
    var params = {
      Param: {
        UserID: getApp().globalData.userId,
        xy_OutTradeNo: this.data.id,
        ModeOfPayment: 1
      },
      Action: 520
    };
    var page = this;
    util.reqMedia(params,function(value){
      wx.requestPayment({
        timeStamp: value.timestamp,
        nonceStr: value.noncestr,
        package: 'prepay_id=' + value.prepayid,
        signType: 'MD5',
        paySign: value.sign,
        success: function (res) {
      
          wx.navigateTo({
            url: '/pages/afterPay/afterPay?detail=' + JSON.stringify(page.data.detail),
          });
        }
      });
    });
  }
});